package org.xlh.springboot.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.xlh.springboot.bean.User;
import org.xlh.springboot.bean.Vip;
import org.xlh.springboot.enums.CodeEnum;
import org.xlh.springboot.result.R;
import org.xlh.springboot.service.VipService;
import org.xlh.springboot.util.Constant;

import java.util.List;

@RestController
public class VipController {

    @Autowired
    private VipService vipService;

//    @GetMapping("/list/{pageNo}")
//    public PageInfo<Vip> list(@PathVariable("pageNo") int pageNo) {
//        //1.设置当前页面和每页显示的记录条数条数
//        //这行代码只要执行，将来执行sql语句时，会自动添加limit，比较方便
//        PageHelper.startPage(pageNo, Constant.PAGE_SIZE);
//        //2.查询数据
//        List<Vip> vips = vipService.selectAll();
//        //3.将数据封装到PageInfo对象中
//        PageInfo<Vip> vipPageInfo = new PageInfo<>(vips);
//        return vipPageInfo;
//    }

    @GetMapping("/list/{pageNo}")
    public R<PageInfo<Vip>> list(@PathVariable("pageNo") int pageNo) {
        PageHelper.startPage(pageNo, Constant.PAGE_SIZE);
        List<Vip> vips = vipService.selectAll();
        PageInfo<Vip> vipPageInfo = new PageInfo<>(vips);
        return R.OK(vipPageInfo);
    }

    @GetMapping("/detail")
    public R<User> detail(){
        //return R.OK(new User("jack",20));
        //return R.OK();
        //return R.FAIL();
        //return R.FAIL(404,"资源找不到");
        return R.FAIL(CodeEnum.NOT_FOUND);
    }
}
